import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:validatorless/validatorless.dart';
import 'package:zz_listen_english/common/index.dart';
import 'package:zz_listen_english/common/widgets/text_widget.dart';


import 'index.dart';

class HttpIpSetPage extends GetView<HttpIpSetController> {
  const HttpIpSetPage({Key? key}) : super(key: key);

  Widget _buildFrom() {
    return Form(
        key: controller.fromKey,
        autovalidateMode: AutovalidateMode.onUserInteraction,
        child: <Widget>[
          //用户名
          TextFormWidget(
              autofocus: true,
              controller: controller.ipController,
              labelText: 'ip:',
              validator: Validatorless.multiple([
                Validatorless.required("不能为空！"),
              ])).paddingBottom(20),

          //密码
          TextFormWidget(
              controller: controller.portController,
              labelText: '端口号:',
              validator: Validatorless.multiple([
                Validatorless.required("不能为空！"),
              ])).paddingBottom(20),
          FormField<bool>(
            initialValue: false,
            validator: (value) {
              return null;
            },
            builder: (formFieldState) {
              return Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  const TextWidget(
                    text: "协议:",
                    size: 12,
                  ),
                  Row(
                    children: [
                      Checkbox(
                          value: !controller.checkValue,
                          onChanged: (value) {
                            formFieldState.didChange(value);
                            controller.checkValue = !value!;
                          }),
                      const Text("Http"),
                      const SizedBox(
                        width: 50,
                      ),
                      Checkbox(
                          value: controller.checkValue,
                          onChanged: (value) {
                            formFieldState.didChange(value);
                            controller.checkValue = value!;
                          }),
                      const Text("Https"),
                    ],
                  ),
                  if (!formFieldState.isValid)
                    Text(formFieldState.errorText ?? ""),
                ],
              );
            },
          ).paddingBottom(40),
           ElevatedButton(child:Text('确定'), onPressed: controller.onSave)
               .paddingBottom(30.w),
        ].toColumn().paddingAll(20));
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<HttpIpSetController>(
      init: HttpIpSetController(),
      id: "http_ip_set",
      builder: (_) {
        return Scaffold(
          appBar: AppBar(title: const Text("设置ip")),
          body: SafeArea(
            child: _buildFrom(),
          ),
        );
      },
    );
  }
}
